/*
 * Amenities Module Configuration GUI
 */

// functions

RM.Pages.Functions.Amenities_Config_Toolbar = {
    xtype : "panel",
    id : "rm_pages_modules_amenities_toolbar",
    bodyBorder : false,
    html : RM.Common.getToolbar([{image: RM.BaseLargeImageURL+"save.gif", label: RM.Translate.Common.Save, link: "RM.Pages.Functions.Amenities_Config_save()"}])
};
RM.Toolbars.push(RM.Pages.Functions.Amenities_Config_Toolbar);

RM.Pages.Functions.Amenities_Config_save = function(){
    RM.Pages.Amenities_Config_Panel.getForm().submit({
        success: function(form, action) {
            var statusbar = Ext.getCmp('rm_pages_modules_amenities_config_statusbar');
            statusbar.setStatus({
                text: RM.Translate.Admin.Amenities.Config.SaveOK,
                iconCls: 'ok-icon'
            });
        },
        failure: function() {
            var statusbar = Ext.getCmp('rm_pages_modules_amenities_config_statusbar');
            statusbar.setStatus({
                text: RM.Translate.Common.Failed,
                iconCls: 'failed-icon'
            });
        },
        waitMsg: RM.Translate.Common.Saving,
        waitTitle: RM.Translate.Common.PleaseWait
    });
};

RM.Pages.Functions.Amenities_ConfigJson = function(responseObject) {

    // create a mask assigned to rm_pages_plugins_gmaps_main_form
    var myMask = new Ext.LoadMask('rm_pages_modules_amenities_config_main_form', {
        msg: RM.Translate.Common.PleaseWait,
        msgCls: "RM_Loading_Mask_Msg_Hidden" // hide the msg
    });
    myMask.show();

    Ext.getCmp("rm_pages_modules_amenities_height").setValue(responseObject.settings.icon_height);
    Ext.getCmp("rm_pages_modules_amenities_showonlist").setValue(responseObject.settings.show_list);
    Ext.getCmp("rm_pages_modules_amenities_showondetails").setValue(responseObject.settings.show_details);

    // render the forms and toolbars
    Ext.getCmp('rm_pages_modules_amenities_config_main_form').render();
    Ext.getCmp('rm_pages_modules_amenities_config_main_form').doLayout();
    Ext.getCmp('toolbar_panel').layout.setActiveItem('rm_pages_modules_amenities_toolbar');
    Ext.getCmp('content-panel').layout.setActiveItem('rm_pages_modules_amenities_config_main_form');

    myMask.hide();
    RM.Help.Load('Admin.Amenities.Config');
};

// form objects
RM.Pages.Amenities_Config_Height = {
    xtype : "textfield",
    id : "rm_pages_modules_amenities_height",
    name : "rm_pages_modules_amenities_height",
    fieldLabel : RM.Translate.Admin.Amenities.Config.Height,
    width : 80
};
RM.Pages.Amenities_Config_ShowOnList = {
    id: "rm_pages_modules_amenities_showonlist",
    name: "rm_pages_modules_amenities_showonlist",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.Amenities.Config.ShowOnList,
    xtype: "xcheckbox"
};
RM.Pages.Amenities_Config_ShowOnDetails = {
    id: "rm_pages_modules_amenities_showondetails",
    name: "rm_pages_modules_amenities_showondetails",
    inputValue: "1",
    fieldLabel: RM.Translate.Admin.Amenities.Config.ShowOnDetails,
    xtype: "xcheckbox"
};

RM.Pages.Amenities_Config_Settings_Fieldset = new Ext.form.FieldSet({
    id: "rm_pages_modules_amenities_config_fieldset",
    title: RM.Translate.Admin.Amenities.Config.Settings,
    autoHeight: true,
    layout: 'form',
    bodyBorder : false,
    items: [
        RM.Pages.Amenities_Config_Height,
        RM.Pages.Amenities_Config_ShowOnList,
        RM.Pages.Amenities_Config_ShowOnDetails
    ]
});

RM.Pages.Amenities_Config_Panel = new Ext.FormPanel({
    id : 'rm_pages_modules_amenities_config_main_form',
    title: RM.Translate.Admin.Amenities.Config.Title,
    bodyStyle : "padding:10px;",
    items : [
        RM.Pages.Amenities_Config_Settings_Fieldset
    ],
    url : RM.Common.AssembleURL({
        controller: 'Amenities',
        action: 'updateconfigjson'
    }),
    bbar: new Ext.ux.StatusBar({
        id: 'rm_pages_modules_amenities_config_statusbar',
        items: []
    })
});

RM.Main.Pages.push(RM.Pages.Amenities_Config_Panel);